package com.job.ZhangMeng.Homework0718;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * 2022.07.18  彩票摇奖
 * 张孟
 */

public class Roll {

    static int[] generatePrize(){   //生成获奖号码
        Random ran=new Random();
        int[] prize=new int[7],temp=new int[7];
        for (int i = 0; i < 7; i++) {
            temp[i]=ran.nextInt(33)+1; //[0,33)+1 -> [1,34)
            if(noRepeat(prize,temp[i]))
                prize[i]=temp[i];
            else{    //如果有重复数字,直接退出程序,重新运行生成另一串获奖号码
                prize[i]=temp[i];
                System.out.println(Arrays.toString(prize));
                System.out.println("有重复数字,请重新生成获奖号码!");
                System.exit(-1);
            }
        }
        return prize;
    }

    static void judgeGrade(int[] purchaseTicket,int[] prize){   //判断获奖等级
        int count=0,num;
        for (int i = 0; i < prize.length; i++) {    //进行7轮(同时遍历prize)
            num=prize[i];
            for (int j = 0; j < purchaseTicket.length; j++) {   //每轮遍历purchaseTicket,查看有无prize[i]
                if(purchaseTicket[j]==num)
                    count+=1;
            }
        }
        switch (count){
            case 0:System.out.println("很遗憾,您未能中奖.");break;
            case 1:System.out.println("恭喜您,您获得了六等奖!");break;
            case 2:System.out.println("恭喜您,您获得了五等奖!");break;
            case 3:System.out.println("恭喜您,您获得了四等奖!");break;
            case 4:System.out.println("恭喜您,您获得了三等奖!");break;
            case 5:System.out.println("恭喜您,您获得了二等奖!");break;
            case 6:System.out.println("恭喜您,您获得了一等奖!");break;
            case 7:System.out.println("头奖!");break;
        }
    }

    static boolean noRepeat(int[] arr,int num){ //判断获奖号码有无重复数字
        for (int i = 0; i < arr.length; i++) {  //遍历arr(prize)
            if(arr[i]==num){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int[] prize=generatePrize();
        int[] ticket=new int[7];
        Scanner ch=new Scanner(System.in);
        for (int i = 0; i < 5; i++) {
            System.out.print("请输入您购买的第"+(i+1)+"张彩票(1~33):");
            for (int j = 0; j < 7; j++) {
                int number=ch.nextInt();
                ticket[j]=number;
            }
            judgeGrade(ticket, prize);
        }
        System.out.println("\n中奖号码为:"+ Arrays.toString(prize));
    }

}
